cbpAnimatedHeader.js ➔ scrollPage   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 10
rs 9.4285
1
/**
2
 * cbpAnimatedHeader.js v1.0.0
3
 * http://www.codrops.com
4
 *
5
 * Licensed under the MIT license.
6
 * http://www.opensource.org/licenses/mit-license.php
7
 * 
8
 * Copyright 2013, Codrops
9
 * http://www.codrops.com
10
 */
11
var cbpAnimatedHeader = (function() {
12
13
	var docElem = document.documentElement,
14
		header = document.querySelector( '.navbar-default' ),
15
		didScroll = false,
16
		changeHeaderOn = 300;
17
18
	function init() {
19
		window.addEventListener( 'scroll', function( event ) {
0 ignored issues
show
Unused Code introduced by
The parameter event is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
20
			if( !didScroll ) {
21
				didScroll = true;
22
				setTimeout( scrollPage, 250 );
23
			}
24
		}, false );
25
	}
26
27
	function scrollPage() {
28
		var sy = scrollY();
29
		if ( sy >= changeHeaderOn ) {
30
			classie.add( header, 'navbar-shrink' );
0 ignored issues
show
Bug introduced by
The variable classie seems to be never declared. If this is a global, consider adding a /** global: classie */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
31
		}
32
		else {
33
			classie.remove( header, 'navbar-shrink' );
34
		}
35
		didScroll = false;
36
	}
37
38
	function scrollY() {
39
		return window.pageYOffset || docElem.scrollTop;
40
	}
41
42
	init();
43
44
})();